import { FormProps } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import {
  projectTypeListApi,
  projectManagerListApi,
  projectTemplateListApi,
  projectParticipantsListApi,
} from '/@/api/demo/project';
import { useUserStore } from '/@/store/modules/user';
import { FormSchema } from '/@/components/Form';

const useCommonStore = useUserStore();

// 新增项目表单数据
export function getAddProject(): FormSchema[] {
  return [
    {
      field: 'name',
      component: 'Input',
      label: '项目名称',
      required: true,
      componentProps: {
        placeholder: '请输入项目名称',
      },
    },
    {
      field: 'product',
      component: 'ApiSelect',
      label: '项目模板',
      componentProps: {
        placeholder: '请输入项目模板',
        api: projectTemplateListApi,
        dropdownStyle: { maxHeight: '150px', overflow: 'auto' },
        labelField: 'templateName',
        valueField: 'id',
        showSearch: true,
        filterOption: (input, option) => {
          return option.label.indexOf(input.toLowerCase()) >= 0;
        },
        onChange: (e: ChangeEvent) => {
          console.log(e, '修改');
        },
      },
    },
    {
      field: 'participant',
      component: 'ApiTreeSelect',
      label: '项目参与人',
      required: true,
      componentProps: {
        placeholder: '请输入项目参与人',
        api: projectParticipantsListApi,
        multiple: true,
        dropdownStyle: { maxHeight: '150px', overflow: 'auto' },
        showSearch: true,
        filterTreeNode: (inputValue, treeNode) => {
          return treeNode.props.title.includes(inputValue);
        },
      },
    },
    {
      field: 'manager',
      component: 'ApiSelect',
      label: '项目负责人',
      required: true,
      componentProps: {
        placeholder: '请输入项目负责人',
        api: projectManagerListApi,
        dropdownStyle: { maxHeight: '120px', overflow: 'auto' },
        params: {
          userid: useCommonStore.userInfo?.userId,
        },
        labelField: 'name',
        valueField: 'userid',
        showSearch: true,
        filterOption: (input, option) => {
          return option.label.indexOf(input.toLowerCase()) >= 0;
        },
      },
    },
    {
      field: 'planTime',
      component: 'RangePicker',
      label: '计划起始时间',
      required: true,
    },
  ];
}
// 全部项目表格数据
export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '项目名称',
      dataIndex: 'name',
      fixed: 'left',
      width: 300,
    },
    {
      title: '项目状态',
      dataIndex: 'status',
      width: 100,
      slots: { customRender: 'status' },
    },
    {
      title: '负责人',
      dataIndex: 'managerName',
      width: 100,
    },
    {
      title: '需求方',
      dataIndex: 'customer',
      width: 100,
    },
    {
      title: '计划开始时间',
      width: 150,
      sorter: (a, b) => {
        return a.prestarttime > b.prestarttime ? 1 : -1;
      },
      dataIndex: 'prestarttime',
      slots: { customRender: 'prestarttime' },
    },
    {
      title: '计划结束时间',
      width: 150,
      sorter: (a, b) => {
        return a.preEndTime > b.preEndTime ? 1 : -1;
      },
      dataIndex: 'preEndTime',
      slots: { customRender: 'preEndTime' },
    },
    {
      title: '实际进度',
      dataIndex: 'overdue',
      width: 150,
      sorter: (a, b) => {
        return a.overdue > b.overdue ? 1 : -1;
      },
      slots: { customRender: 'overdue' },
    },
    {
      title: '完成比例',
      dataIndex: 'completeRatio',
      width: 150,
      sorter: (a, b) => {
        return a.completeRatio > b.completeRatio ? 1 : -1;
      },
      slots: { customRender: 'completeRatio' },
    },
    {
      title: '实际累计成本',
      dataIndex: 'reallyCost',
      width: 150,
    },
    {
      title: '成本差距',
      dataIndex: 'costDifference',
      width: 150,
      slots: { customRender: 'costDifference' },
    },
    {
      title: '综合评估',
      dataIndex: 'taskfilescore',
      width: 150,
    },
    {
      title: '创建人',
      dataIndex: 'creatorName',
      width: 150,
    },
    {
      title: '创建时间',
      dataIndex: 'creationTime',
      width: 150,
      sorter: (a, b) => {
        return a.creationTime > b.creationTime ? 1 : -1;
      },
      slots: { customRender: 'creationTime' },
    },
    {
      title: '备注',
      dataIndex: 'notes',
      width: 200,
    },
  ];
}
// 全部项目搜索表单数据
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    colon: false, // 是否显示冒号
    schemas: [
      {
        field: `proname`,
        label: `项目名称`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: '请输入项目名称',
        },
      },
      {
        field: `status`,
        label: `项目状态`,
        component: 'Select',
        componentProps: {
          placeholder: '请选择项目状态',
          options: [
            {
              value: '0',
              label: '未开始',
            },
            {
              value: '1',
              label: '进行中',
            },
            {
              value: '2',
              label: '已暂停',
            },
          ],
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `proType`,
        label: `项目类型`,
        component: 'ApiSelect',
        componentProps: {
          placeholder: '请选择项目类型',
          api: projectTypeListApi,
          params: {
            TypeName: '项目类型',
          },
          labelField: 'resourceName',
          valueField: 'id',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `Manager`,
        label: `负责人`,
        component: 'ApiSelect',
        componentProps: {
          placeholder: '请选择负责人',
          api: projectManagerListApi,
          params: {
            userid: useCommonStore.userInfo?.userId,
          },
          labelField: 'name',
          valueField: 'userid',
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `customer`,
        label: `需求方`,
        component: 'Input',
        componentProps: {
          placeholder: '请选择需求方',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `planTime`,
        label: `计划时间`,
        component: 'RangePicker',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `isshare`,
        label: `分享项目`,
        component: 'Switch',
        componentProps: {
          checkedChildren: '是',
          unCheckedChildren: '否',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
    fieldMapToTime: [['planTime', ['prestartime', 'preendtime'], 'YYYY-MM-DD']],
  };
}

//项目详情-项目参与人表格
export function getDetailColumns(): BasicColumn[] {
  return [
    {
      title: '成员',
      dataIndex: 'name',
      fixed: 'left',
      width: 150,
    },
    {
      title: '角色',
      dataIndex: 'role',
      width: 150,
    },
  ];
}

//任务管理表格数据
export function getTaskManagerColumns(): BasicColumn[] {
  return [
    {
      title: '任务名称',
      dataIndex: 'newName',
      align: 'left',
      fixed: 'left',
      width: 300,
      slots: { customRender: 'newName' },
    },
    {
      title: '计划开始时间',
      dataIndex: 'strPlanStartTime',
      width: 150,
      align: 'center',
      sorter: (a, b) => {
        return a.strPlanStartTime > b.strPlanStartTime ? 1 : -1;
      },
      slots: { customRender: 'strPlanStartTime' },
    },
    {
      title: '工期',
      dataIndex: 'workDays',
      width: 120,
      align: 'center',
      defaultHidden: true,
    },
    {
      title: '计划结束时间',
      dataIndex: 'strPlanEndTime',
      width: 150,
      align: 'center',
      sorter: (a, b) => {
        return a.strPlanEndTime > b.strPlanEndTime ? 1 : -1;
      },
      slots: { customRender: 'strPlanEndTime' },
    },
    {
      title: '实际开始时间',
      dataIndex: 'strReallyStartTime',
      width: 150,
      align: 'center',
      defaultHidden: true,
      sorter: (a, b) => {
        return a.strReallyStartTime > b.strReallyStartTime ? 1 : -1;
      },
      slots: { customRender: 'strReallyStartTime' },
    },
    {
      title: '实际工期',
      dataIndex: 'reallyWorkDays',
      width: 10,
      align: 'center',
      defaultHidden: true,
    },
    {
      title: '实际结束时间',
      dataIndex: 'strReallyEndTime',
      width: 150,
      align: 'center',
      defaultHidden: true,
      sorter: (a, b) => {
        return a.strReallyEndTime > b.strReallyEndTime ? 1 : -1;
      },
      slots: { customRender: 'strReallyEndTime' },
    },
    {
      title: '任务状态',
      dataIndex: 'newState',
      align: 'center',
      width: 120,
      slots: { customRender: 'newState' },
    },
    {
      title: '执行人',
      dataIndex: 'executorName',
      align: 'center',
      width: 120,
    },
    {
      title: '质量评估',
      dataIndex: 'filescore',
      align: 'center',
      width: 120,
      defaultHidden: true,
    },
    {
      title: '前置任务',
      dataIndex: 'predecessorName',
      align: 'center',
      width: 240,
    },
    {
      title: '里程碑',
      dataIndex: 'milestone',
      align: 'center',
      slots: { customRender: 'milestone' },
      width: 80,
    },
    {
      title: '交付件',
      dataIndex: 'approve',
      align: 'center',
      slots: { customRender: 'approve' },
      width: 100,
    },
    {
      title: '计划成本',
      dataIndex: 'costBudget',
      align: 'center',
      width: 100,
    },
    {
      title: '实际成本',
      dataIndex: 'reallyCost',
      align: 'center',
      width: 100,
      defaultHidden: true,
    },
    {
      title: '备注',
      dataIndex: 'process',
      width: 200,
      align: 'center',
    },
    {
      title: '描述',
      dataIndex: 'taskDescription',
      width: 200,
      align: 'center',
      defaultHidden: true,
    },
  ];
}
// 任务管理搜索表单数据
export function getTaskManagerConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    colon: false, // 是否显示冒号
    schemas: [
      {
        field: `Executor`,
        label: `执行人`,
        component: 'ApiSelect',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入执行人',
          labelField: 'name',
          valueField: 'id',
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
      {
        field: `State`,
        label: `任务状态`,
        component: 'Select',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请选择项目状态',
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
          options: [
            {
              value: '0',
              label: '未开始',
            },
            {
              value: '1',
              label: '已开始',
            },
            {
              value: '2',
              label: '正常完成',
            },
            {
              value: '3',
              label: '超期完成',
            },
            {
              value: '4',
              label: '已超期',
            },
            {
              value: '5',
              label: '即将超期',
            },
          ],
        },
      },
      {
        field: `Predecessor`,
        label: `前置任务`,
        component: 'ApiSelect',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入前置任务',
          labelField: 'name',
          valueField: 'id',
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
      {
        field: `CostBudget`,
        label: `计划成本`,
        component: 'Input',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入计划成本',
        },
      },
      {
        field: `Milestone`,
        label: `里程碑`,
        component: 'Select',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入里程碑',
          options: [
            {
              value: '0',
              label: '关闭',
            },
            {
              value: '1',
              label: '开启',
            },
          ],
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
      {
        field: `Approve`,
        label: `交付件`,
        component: 'Select',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入交付件',
          options: [
            {
              value: '0',
              label: '关闭',
            },
            {
              value: '1',
              label: '开启',
            },
          ],
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
      {
        field: `orderby`,
        label: `排序方式`,
        component: 'Select',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入排序方式',
          options: [
            {
              value: '0',
              label: '正序',
            },
            {
              value: '1',
              label: '倒序',
            },
          ],
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
      {
        field: `ordertime`,
        label: `时间排序`,
        component: 'Select',
        colProps: {
          xl: 8,
          xxl: 6,
        },
        componentProps: {
          placeholder: '请输入时间排序',
          options: [
            {
              value: '0',
              label: '开始时间',
            },
            {
              value: '1',
              label: '结束时间',
            },
          ],
          showSearch: true,
          filterOption: (input, option) => {
            return option.label.indexOf(input.toLowerCase()) >= 0;
          },
        },
      },
    ],
  };
}
// 新建任务表单数据
export function getAddTask(): FormSchema[] {
  return [
    {
      field: 'taskNumber',
      component: 'Input',
      label: '任务编号',
      componentProps: {
        placeholder: '请输入任务编号',
      },
    },
    {
      field: 'taskName',
      component: 'Input',
      label: '任务名称',
      required: true,
      componentProps: {
        placeholder: '请输入任务名称',
      },
    },
    {
      field: 'executor',
      component: 'ApiSelect',
      label: '执行人',
      required: true,
      colProps: { span: 12 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入执行人',
      },
    },
    {
      field: 'workTime',
      component: 'ApiSelect',
      label: '计划工时',
      colProps: { span: 12 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入计划工时',
      },
    },
    {
      field: 'predecessor',
      component: 'ApiSelect',
      label: '前置任务',
      componentProps: {
        placeholder: '请输入前置任务',
      },
    },
    {
      field: 'planTime',
      component: 'DatePicker',
      label: '开始时间',
      colProps: { span: 12 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入开始时间',
      },
    },
    {
      field: 'planTime',
      component: 'DatePicker',
      label: '结束时间',
      colProps: { span: 12 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入结束时间',
      },
    },
    {
      field: 'desc',
      component: 'InputTextArea',
      label: '描述',
      componentProps: {
        placeholder: '请输入描述',
      },
    },
  ];
}
// 获取任务详情弹窗数据
export function getTaskDetail(): FormSchema[] {
  return [
    {
      field: 'field1',
      component: 'Input',
      label: '计划工期（天）',
      colProps: { span: 8 },
      componentProps: {
        placeholder: '请输入计划工期',
      },
    },
    {
      field: 'field2',
      component: 'Input',
      label: '计划成本',
      colProps: { span: 8 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入计划成本',
      },
    },
    {
      field: 'field3',
      component: 'Input',
      label: '实际成本',
      colProps: { span: 8 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入实际成本',
      },
    },
    {
      field: 'field4',
      component: 'DatePicker',
      label: '实际开始时间',
      colProps: { span: 8 },
      componentProps: {
        placeholder: '请输入实际开始时间',
      },
    },
    {
      field: 'field5',
      component: 'Input',
      label: '实际工期',
      colProps: { span: 8 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入实际工期',
      },
    },
    {
      field: 'field6',
      component: 'DatePicker',
      label: '实际结束时间',
      colProps: { span: 8 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入实际结束时间',
      },
    },
    {
      field: 'field7',
      component: 'Input',
      label: '质量评估',
      colProps: { span: 8 },
      componentProps: {
        placeholder: '请输入质量评估',
      },
    },
    {
      field: 'field8',
      component: 'ApiSelect',
      label: '前置任务',
      colProps: { span: 16 },
      itemProps: {
        labelCol: { span: 24, offset: 1 },
        wrapperCol: { span: 24, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入前置任务',
      },
    },
    {
      field: 'field9',
      component: 'InputTextArea',
      label: '备注',
      colProps: { span: 24 },
      componentProps: {
        placeholder: '请输入备注',
      },
    },
    {
      field: 'field10',
      component: 'InputTextArea',
      label: '描述',
      colProps: { span: 24 },
      componentProps: {
        placeholder: '请输入描述',
      },
    },
  ];
}

// 分享项目表格
export function getAllShareColoums(): BasicColumn[] {
  return [
    {
      title: '项目名称',
      dataIndex: 'projectName',
      align: 'left',
      fixed: 'left',
      width: 300,
    },
    {
      title: '分享人',
      dataIndex: 'shareUsername',
      width: 150,
      align: 'center',
      slots: { customRender: 'shareUsername' },
    },
    {
      title: '分享开始时间',
      dataIndex: 'shareStarttime',
      width: 150,
      align: 'center',
      sorter: (a, b) => {
        return a.shareStarttime > b.shareStarttime ? 1 : -1;
      },
      slots: { customRender: 'shareStarttime' },
    },
    {
      title: '分享结束时间',
      dataIndex: 'shareEndTime',
      width: 150,
      align: 'center',
      sorter: (a, b) => {
        return a.shareEndTime > b.shareEndTime ? 1 : -1;
      },
      slots: { customRender: 'shareEndTime' },
    },
    {
      title: '是否可用',
      dataIndex: 'canShare',
      width: 150,
      align: 'center',
      slots: { customRender: 'canShare' },
    },
  ];
}

// 新增项目模板
export function getAddProjectTemp(): FormSchema[] {
  return [
    {
      field: 'isClearExecutor',
      component: 'Checkbox',
      label: '清空任务执行人',
      colProps: { span: 24 },
      itemProps: {
        labelCol: { span: 12, offset: 1 },
        wrapperCol: { span: 12, offset: 1 },
      },
    },
    {
      field: 'isClearPreTime',
      component: 'Checkbox',
      label: '清空任务计划开始/结束时间',
      colProps: { span: 24 },
      itemProps: {
        labelCol: { span: 12, offset: 1 },
        wrapperCol: { span: 12, offset: 1 },
      },
    },
  ];
}

// 选择报表打印模板
export function getAddProjectReport(): FormSchema[] {
  return [
    {
      field: 'reportType',
      component: 'RadioGroup',
      label: '选择输出类型',
      colProps: { span: 24 },
      itemProps: {
        labelCol: { span: 6, offset: 1 },
        wrapperCol: { span: 14, offset: 1 },
      },
      defaultValue: 'Project',
      required: true,
      componentProps: {
        options: [
          { label: '项目', value: 'Project' },
          { label: '任务', value: 'Task' },
          { label: '人工', value: 'Work' },
        ],
      },
    },
    {
      field: 'reportTemplate',
      component: 'ApiSelect',
      label: '选择模板',
      colProps: { span: 24 },
      //required: true,
      itemProps: {
        labelCol: { span: 6, offset: 1 },
        wrapperCol: { span: 14, offset: 1 },
      },
      componentProps: {
        placeholder: '请选择模板',
      },
    },
    {
      field: 'reportName',
      component: 'Input',
      label: '报表名称',
      colProps: { span: 24 },
      required: true,
      itemProps: {
        labelCol: { span: 6, offset: 1 },
        wrapperCol: { span: 14, offset: 1 },
      },
      componentProps: {
        placeholder: '请输入报表名称',
      },
    },
  ];
}
